﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using Neocean.Mpa.Configuration;
using Neocean.Mpa.Web;

namespace Neocean.Mpa.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class MpaDbContextFactory : IDesignTimeDbContextFactory<MpaDbContext>
    {
        public MpaDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<MpaDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            MpaDbContextConfigurer.Configure(builder, configuration.GetConnectionString(MpaConsts.ConnectionStringName));

            return new MpaDbContext(builder.Options);
        }
    }
}
